//# sourceURL=inviteCompanyJobDetail.js
layui.element.on('tab(login-user-tabs)', function (layui_obj) {
    var custom_obj = $('#tabTitles')[0].children[layui_obj.index].tabCustomObj;
    var inviteCompanyJobDetail_fn = {
        initRender: function () {
            cmsUtils.setContentTabHeight('inviteCompanyJobContent', 50);
            $('#inviteCompanyJobDetail').attr('hasRender', true);
            if (custom_obj.id) {
                var url = '/inviteCompanyJob/detail/'+custom_obj.id;
                $.get(url, function (data) {
                    console.log(data);
                    inviteCompanyJobDetail_fn.setFormData(data);
                    $('#inviteCompanyJobDetail-industry').attr('lay-verify', 'required');
                    $('#inviteCompanyJobDetail-industry').attr('lay-verType', 'tips');
                    $('#inviteCompanyJobDetail-jobTitle').attr('lay-verify', 'required');
                    $('#inviteCompanyJobDetail-jobTitle').attr('lay-verType', 'tips');
                });
                $('button[lay-filter="inviteCompanyJobDetail-btn-modify"]').show();
            } else {
                $('button[lay-filter="inviteCompanyJobDetail-btn-add"]').show();
                cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/0','inviteCompanyJobDetail-industry','code','value');
                cmsUtils.renderDynamicSelectionBox('/cms/common/combo/result/edu','inviteCompanyJobDetail-eduRequire','code','value');
                $('#inviteCompanyJobDetail-industry').attr('lay-verify', 'required');
                $('#inviteCompanyJobDetail-industry').attr('lay-verType', 'tips');
                $('#inviteCompanyJobDetail-jobTitle').attr('lay-verify', 'required');
                $('#inviteCompanyJobDetail-jobTitle').attr('lay-verType', 'tips');
            }
            layui.form.render(null, 'inviteCompanyJobDetail-form');
        },
        setFormData: function (data) {
            cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/0','inviteCompanyJobDetail-industry','code','value');
            cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/1','inviteCompanyJobDetail-jobTitle','code','value');
            cmsUtils.renderDynamicSelectionBox('/cms/common/combo/result/edu','inviteCompanyJobDetail-eduRequire','code','value');
            cmsUtils.formDataBind('inviteCompanyJobDetail-form', data.data);
            layui.form.render(null, 'inviteCompanyJobDetail-form');
        },
        getFormData: function (data) {
            data.id = custom_obj.id;
            data.jobAddress = $('#inviteCompanyJobDetail-jobAddress').val();
            data.jobDesc = $('#inviteCompanyJobDetail-jobDesc').val();
            data.jobWelfare = $('#inviteCompanyJobDetail-jobWelfare').val();
            data.jobRequire = $('#inviteCompanyJobDetail-jobRequire').val();
            return data;
        },
        submitForm: function (post_params, action, index) {
            console.log(post_params);
            $.ajax({
                type: 'post',
                url: '/inviteCompanyJob/saveOrUpdate',
                data: post_params,
                dataType: 'json',
                success: function (data) {
                    layer.close(index);
                    if (data.code == 200) {
                        switch (action) {
                            case 'close':
                                layui.element.tabDelete('login-user-tabs', 'tab-inviteCompanyJobDetail');
                                custom_obj.list_fn.reload();
                                break;
                        }
                    } else {
                        layer.msg(data.msg ? data.msg : '保存失败', {anim: 6});
                    }
                }
            });
        }
    }
    //下拉框动态加载
    layui.form.on('select(inviteCompanyJobDetail-industry)',function(data){
        $("#inviteCompanyJobDetail-jobTitle").empty();
        $("#inviteCompanyJobDetail-jobTitle").append("<option value=''></option>");
        cmsUtils.renderDynamicSelectionBox('/jobTitle/selectCombo/1?parentId='+data.value,'inviteCompanyJobDetail-jobTitle','code','value');
    });
    if ($('#inviteCompanyJobDetail')[0] && !$('#inviteCompanyJobDetail').attr('hasRender')) {
        inviteCompanyJobDetail_fn.initRender();
        // 设置页面高度
        $(window).resize(function() {
            cmsUtils.setContentTabHeight('inviteCompanyJobDetailContent', 50);
        });
    }
    // 添加
    layui.form.on('submit(inviteCompanyJobDetail-btn-add)', function (data) {
        layer.confirm('确定添加吗？', {
            btn:['确定', '取消']
        }, function (index) {
            inviteCompanyJobDetail_fn.submitForm(inviteCompanyJobDetail_fn.getFormData(data.field), 'close', index);
        });
    });
    // 修改
    layui.form.on('submit(inviteCompanyJobDetail-btn-modify)', function (data) {
        var msg = '确定保存修改信息？';
        layer.confirm(msg, {
            btn:['确定', '取消']
        }, function (index) {
            inviteCompanyJobDetail_fn.submitForm(inviteCompanyJobDetail_fn.getFormData(data.field), 'close', index);
        });
    });
});